<%@page import="org.w3c.dom.Node"%>
<%@page import="org.w3c.dom.Element"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="org.w3c.dom.Document"%>
<%@page import="java.io.StringReader"%>
<%@page import="org.xml.sax.InputSource"%>
<%@page import="javax.xml.parsers.DocumentBuilder"%>
<%@page import="javax.xml.parsers.DocumentBuilderFactory"%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Multicert</title>
	
	<style type="text/css">
		
		p { font-family: times, Times New Roman, times-roman, georgia, serif; font-size: 14px; text-transform: uppercase; color: #444;}
		table { border-collapse:collapse; }
		td, th { border:1px; padding:1px; font-family: times, Times New Roman, times-roman, georgia, serif; font-size: 13px; line-height: 16px; text-transform: uppercase; color: #444;}
		
	</style>
	
</head>
<body>

<form method = 'POST' action = './multicert.jsp'><p>Country Code:&nbsp;<input type = 'text' name = 'inputString'>&nbsp;&nbsp;<input type = 'submit' value = 'Get Data'/></p></form>

<jsp:useBean id="ServicoAid" scope="session" class="com.multicert.ServicoA" />

<%! private String temp; %>

<%

String inputString = request.getParameter("inputString");

if (inputString != null && !inputString.equals("")) {
	
	String result = ServicoAid.getCountryInfo(inputString);
	
	if (result == null){
		
		out.print("<p>Ups! Falhou...</p>");
	}
	else {
		
		try {
			
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();

			InputSource is = new InputSource();
			is.setCharacterStream(new StringReader(result));

			Document doc = builder.parse(is);
			Element root = doc.getDocumentElement();
		
			NodeList nodes = root.getChildNodes();

%>
		
<BR><table>
		
<%

			for (int aux = 0; aux < nodes.getLength(); aux++){
			
				Node node = nodes.item(aux);
			
				out.print("<tr><td>"+node.getNodeName()+":</td><td>"+node.getTextContent()+"</td></tr>");
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		 
%>
		
</table>
		
<%
	}
}

%>

</body>
</html>